<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/resources/layui/css/layui.css">
<link rel="stylesheet" href="${ctx}/resources/layui_ext/dtree/dtree.css">
<link rel="stylesheet" href="${ctx}/resources/layui_ext/dtree/font/dtreefont.css">
</head>
<body>
	<!-- 搜索条件开始 -->
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	  <legend>查询条件</legend>
	</fieldset>
	<form class="layui-form" method="post" id="searchFrm">
		<div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">登陆名称:</label>
		      <div class="layui-input-inline">
		        <input type="text" name="loginname"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">登陆IP:</label>
		      <div class="layui-input-inline">
		        <input type="text" name="loginip"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">开始时间:</label>
		      <div class="layui-input-inline">
		        <input type="text" name="startTime" id="startTime" readonly="readonly"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">结束时间:</label>
		      <div class="layui-input-inline">
		        <input type="text" name="endTime"  id="endTime" readonly="readonly" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" id="doSearch">查询</button>
		      <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
		    </div>
		 </div>
	</form>
	
	<!-- 搜索条件结束 -->
	
	
	<!-- 数据表格开始 -->
	<table class="layui-hide" id="roleTable" lay-filter="roleTable"></table>
	<div style="display: none;" id="roleToolBar">
		    <button type="button" class="layui-btn layui-btn-sm" lay-event="batchDelete">批量删除</button>
	</div>
	<div  id="roleBar" style="display: none;">
	  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</div>
	<!-- 数据表格结束 -->
	
	
	<div style="display: none;" id="selectRoleMenu">
		<ul id="menuTree" class="dtree" data-id="0"></ul>
	</div>
	
	<script src="${ctx}/resources/layui/layui.js"></script>
	<script type="text/javascript">
		var tableIns
		  layui.extend({
			    dtree: '${ctx}/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
			  }).use([ 'jquery', 'layer', 'form', 'table','laydate','dtree' ], function() {
			var $ = layui.jquery;
			var layer = layui.layer;
			var form = layui.form;
			var table = layui.table;
			var laydate=layui.laydate;
			var dtree = layui.dtree;
			
			//绑定时间选择器
			laydate.render({
				elem:'#startTime',
				type:'datetime'
			});
			laydate.render({
				elem:'#endTime',
				type:'datetime'
			})
			
			
			//渲染数据表格
			tableIns=table.render({
				 elem: '#roleTable'   //渲染的目标对象
			    ,url:'${ctx}/logInfo/loadAllLogInfo.action' //数据接口
			    ,title: '用户数据表'//数据导出来的标题
			    ,toolbar:"#roleToolBar"   //表格的工具条
			    //,height:'full-300'
			    ,cellMinWidth:100 //设置列的最小默认宽度
			    ,page: true  //是否启用分页
			    ,cols: [[   //列表数据
				     {type: 'checkbox', fixed: 'left'}
				      ,{field:'id', title:'ID',align:'center',width:'80'}
				      ,{field:'loginname', title:'登陆用户名',align:'center',width:'150'}
				      ,{field:'loginip', title:'登陆IP',align:'center',width:'200'}
				      ,{field:'logintime', title:'登陆时间',align:'center',width:'200'}
				      ,{fixed: 'right', title:'操作', toolbar: '#roleBar', width:'200',align:'center'}
				    ]]
				,done:function(data,curr,count){
			    	//不是第一页时如果当前返回的的数据为0那么就返回上一页
			    	console.log(data)
			    	if(data.data.length==0&&curr!=1){
			    		tableIns.reload({
						    page:{ curr:curr-1 }
						});
			    	}
			    }
			})
			$("#doSearch").click(function (){
				var parms = $("#searchFrm").serialize();
				tableIns.reload({
					url:'${ctx}/logInfo/loadAllLogInfo.action?'+parms
					,page:{curr:1}
				})
			})

			//监听行工具事件
		   table.on('tool(roleTable)', function(obj){
			   var data = obj.data; //获得当前行数据
			   var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			  if(layEvent === 'del'){ //删除
				 deleterole(data);
			   }
			 });
			
			
			
			//监听头部工具栏事件
			table.on("toolbar(roleTable)",function(obj){
				 switch(obj.event){
				    case 'batchDelete':
			    		deleteBatch();
				    break;
				  };
			})
			
			function deleterole(data){
				layer.confirm('真的删除【'+data.loginname+'】这个角色吗', function(index){
					$.post("${ctx}/logInfo/deleteLogInfo.action",{id:data.id},function(res){
						layer.close(index);
						tableIns.reload();
					})
				});
			}
			
			function deleteBatch(){
				var checkStatus = table.checkStatus('roleTable');
				var data = checkStatus.data;
				var params="";
				$.each(data,function(i,item){
			    	if(i==0){
			    		params+="ids="+item.id;
			    	}else{
			    		params+="&ids="+item.id;
			    	}
			    });
			    layer.confirm('真的删除选中的这些角色吗', function(index){
				   console.log(params)
			       $.post("${ctx}/logInfo/deleteBatchLogInfo.action",params,function(res){
			    	   layer.msg(res.msg);
			    	   tableIns.reload();
			       })
			     }); 
			}
			
		});
	</script>
</body>
</html>